package com.ruoyi.psi.inventory.in.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.psi.inventory.in.domain.InventoryIn;
import com.ruoyi.psi.inventory.in.service.IInventoryInService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 其他入库
 */
@RestController
@RequestMapping("/psi/inventory/in")
@Api(value = "其他入库信息模块", tags = "其他入库接口")
public class InventoryInController extends BaseController {
    @Autowired
    private IInventoryInService inventoryInService;

    /**
     * 获取其他入库
     * @param inventoryIn
     * @return
     */
    @ApiOperationSupport(includeParameters = {"InventoryIn.inventoryInId", "InventoryIn.staffId", "InventoryIn.createTime"})
    @ApiOperation(value = "获取其他入库列表",notes = "查询所有其他入库信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody InventoryIn inventoryIn) {
        startPage();
        List<InventoryIn> inventoryIns = inventoryInService.selectInventoryInList(inventoryIn);
        return getDataTable(inventoryIns);
    }

    /**
     * 导出其他入库
     *
     * @param inventoryIn
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody InventoryIn inventoryIn) {
        List<InventoryIn> inventoryIns = inventoryInService.selectInventoryInList(inventoryIn);
        ExcelUtil<InventoryIn> util = new ExcelUtil<InventoryIn>(InventoryIn.class);
        return util.exportExcel(inventoryIns, "其他入库单数据");
    }

    /**
     * 新增其他入库
     * @param inventoryIn 其他入库单据
     * @return
     */
    @ApiOperation(value = "新增其他入库", notes = "新增其他入库")
    @ApiImplicitParam(name = "inventoryIn", value = "新增其他入库", dataType = "InventoryIn")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody InventoryIn inventoryIn) {
        try {
            inventoryInService.insertInventoryIn(inventoryIn);
            return AjaxResult.success("新增成功");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("新增失败");
        }
    }

    /**
     *
     * 更新其他入库
     * @param inventoryIn 其他入库单据
     * @return
     */
    @ApiOperation(value = "更新其他入库", notes = "更新其他入库")
    @ApiImplicitParam(name = "inventoryIn", value = "更新其他入库", dataType = "InventoryIn")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody InventoryIn inventoryIn) {
        try {
            inventoryInService.updateInventoryIn(inventoryIn);
            return AjaxResult.success("修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("修改失败");
        }
    }

    /**
     * 删除其他入库
     * 仅修改删除标志位
     *
     * @param inventoryIn 其他入库单据
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody InventoryIn inventoryIn) {

        return toAjax(inventoryInService.updateInventoryInDeleteFlag(inventoryIn));
    }

}
